
import cv2
from cv2 import VideoWriter, VideoWriter_fourcc, imread, resize
import os
from PIL import Image

def Video2Pic():
    videoPath = "./basket320p.mp4"  # 读取视频路径
    imgPath = "./LRimgs/"  # 保存图片路径
 
    cap = cv2.VideoCapture(videoPath)
    fps = cap.get(cv2.CAP_PROP_FPS)  # 获取帧率
    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))  # 获取宽度
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))  # 获取高度
    suc = cap.isOpened()  # 是否成功打开
    frame_count = 0
    while suc:
        frame_count += 1
        suc, frame = cap.read()
        #cv2.imwrite(imgPath + str(frame_count).zfill(4), frame)
        cv2.imwrite(imgPath + "%d.jpg" %frame_count, frame)
        cv2.waitKey(1)
    cap.release()
    print("视频转图片结束！")
     
     
if __name__ == '__main__':
    Video2Pic()
